package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgImages;
import com.ygqh.baby.service.YgImagesService;
import com.ygqh.baby.utils.JsonUtils;

@Controller
@RequestMapping("/admin/images")
public class ImagesController extends BaseController<Object, java.lang.Long>{
   @Autowired
	private YgImagesService ygImagesService;
	@RequestMapping("searchImages")
	@ResponseBody
	public Map<String,Object> searchImages(String q,QueryInfo queryInfo)  {	
		
		ResultSet<YgImages> resultSet=ygImagesService.search(queryInfo,q);
		return resultSet.toDatatables(null);
	}

	@RequestMapping("saveImages")
	@ResponseBody
	public Message saveImages(String images) {
		YgImages ygImages=JsonUtils.toObject(images, YgImages.class);		
		ygImages.setCreateBy(getSession().getTrueName());
		ygImages.setCreateTime(new Date());
	   return ygImagesService.saveOrUpdate(ygImages)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}

	@RequestMapping("updateImages")
	@ResponseBody
	public Message updateImages(Long id) {
		YgImages ygImages=new YgImages();	
		ygImages.setId(id);
		ygImages.setStatus(DataStatus.Delete);
		ygImages.setUpdateBy(getSession().getTrueName());
		ygImages.setUpdateTime(new Date());
	   return ygImagesService.update(ygImages)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
}
